import Vue from 'vue';
import App from './app.vue';
import underscore from 'vue-underscore';
import router from '@/router/router.js';
import MyForm from '@/components/Form';
import MyTable from '@/components/Table';
import MyUpload from '@/components/Upload/MyUpload.vue';
import QuillEditor from '@/components/QuillEditor';

// 全局组件
Vue.component('MyForm', MyForm);
Vue.component('MyTable', MyTable);
Vue.component('MyUpload', MyUpload);
Vue.component('QuillEditor', QuillEditor);

import commonUtil from '@/utils/common.js';
Vue.prototype.$commonUtil = commonUtil;

Vue.config.devtools = true;

import '@babel/polyfill';
import 'proto-polyfill';


// 引入element ui
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import {
	Msg
} from '@/utils/resetMessage.js';
Vue.use(ElementUI);
Vue.prototype.$message = Msg;


import '@/assets/images/icon/iconfont.css';
import '@/assets/styles/app.scss'; // global css
import '@/assets/styles/login.scss'; // global css
import '@/assets/styles/bg_index.scss'; // global css

// 自定义 axios
import * as axs from '@/api/common.js';
Vue.prototype.$ax = axs;


// import * as  echarts from 'echarts';
// Vue.prototype.$echarts = echarts;


import store from '@/store/main.js';
Vue.prototype.$store = store;

Vue.use(router);
Vue.use(underscore);

const root = document.createElement('div');
document.body.appendChild(root);


new Vue({
	router,
	data: {
		eventHub: new Vue()
	},
	beforeCreate() {
		var lastTime = 0;
		var vendors = ['ms', 'moz', 'webkit', 'o'];
		for (var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) {
			window.requestAnimationFrame =
				window[vendors[x] + 'RequestAnimationFrame'];
			window.cancelAnimationFrame =
				window[vendors[x] + 'CancelAnimationFrame'] ||
				window[vendors[x] + 'CancelRequestAnimationFrame'];
		}

		if (!window.requestAnimationFrame) {
			// window.requestAnimationFrame = function(callback, element) {
			window.requestAnimationFrame = function (callback) {
				var currTime = new Date().getTime();
				var timeToCall = Math.max(0, 16 - (currTime - lastTime));
				var id = window.setTimeout(function () {
					callback(currTime + timeToCall);
				}, timeToCall);
				lastTime = currTime + timeToCall;
				return id;
			};
		}

		if (!window.cancelAnimationFrame) {
			window.cancelAnimationFrame = function (id) {
				clearTimeout(id);
			};
		}

		if (
			Function.prototype.bind &&
			window.console &&
			typeof console.log == 'object'
		) {
			[
				'log',
				'info',
				'warn',
				'error',
				'assert',
				'dir',
				'clear',
				'profile',
				'profileEnd'
			].forEach(function (method) {
				console[method] = this.bind(console[method], console);
			}, Function.prototype.call);
		}
	},
	render: h => h(App),
}).$mount(root);

